package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * saas菜单汇总
 *
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/1/25 10:19
 * @since v1.0
 */
@Getter
public enum SaasMenuEnum {
    /**
     * 菜单
     */
    CUSTOMER(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getI18nName(), true),
    CONTRACT(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.CONTRACT.getI18nName(), true),
    SALES_OPPORTUNITY(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), XbbRefTypeEnum.SALES_OPPORTUNITY.getI18nName(), true),
    CONTACT(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.CONTACT.getCode(), XbbRefTypeEnum.CONTACT.getI18nName(), false),
    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getI18nName(), true),
    COMMUNICATE_PLAN(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), XbbRefTypeEnum.COMMUNICATE_PLAN.getI18nName(), true),
    SUPPLIER(XbbRefTypeEnum.JXC.getCode(), XbbRefTypeEnum.JXC.getI18nName(), XbbRefTypeEnum.SUPPLIER.getCode(), XbbRefTypeEnum.SUPPLIER.getI18nName(), false),
    QUOTATION(XbbRefTypeEnum.CRM.getCode(), XbbRefTypeEnum.CRM.getI18nName(), XbbRefTypeEnum.QUOTATION.getCode(), XbbRefTypeEnum.QUOTATION.getI18nName(), false),
    ;

    private Integer type;
    private String menuName;
    private Integer subType;
    private String subMenuName;
    private Boolean companyConfig;

    SaasMenuEnum(Integer type, String menuName, Integer subType, String subMenuName, Boolean companyConfig) {
        this.type = type;
        this.menuName = menuName;
        this.subType = subType;
        this.subMenuName = subMenuName;
        this.companyConfig = companyConfig;
    }

    public static List<SaasMenuEnum> getByType(Integer type) {
        List<SaasMenuEnum> saasMenuEnumList = new ArrayList<>();
        for (SaasMenuEnum cacheCode : values()) {
            if (type.equals(cacheCode.getType())) {
                saasMenuEnumList.add(cacheCode);
            }
        }
        return saasMenuEnumList;
    }

    public static SaasMenuEnum getBySubType(Integer subType) {
        for (SaasMenuEnum cacheCode : values()) {
            if (subType.equals(cacheCode.getSubType())) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getMenuName() {
        return I18nMessageUtil.getMessage(menuName);
    }

    public String getSubMenuName() {
        return I18nMessageUtil.getMessage(subMenuName);
    }
}
